package org.xml.xpath4js.client;

/* 
xpath4js is a GWT implementation of XPath 2.0 
Copyright (C) 2010  Peter Schonefeld (peter dot schonefeld at gmail)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.util.HashMap;
import java.util.Vector;

public class XPathDynamicEnv {

	public XPathStaticEnv StatEnv;
	/**
     * @gwt.typeArgs <java.lang.String, com.artbase.xpath.client.XPathVar>
     */			
	public HashMap Variables = new HashMap();
	
	public XPathSequence Focus = new XPathSequence(); //this is the sequence that contains the context item
	/**
     * @gwt.typeArgs <com.artbase.xpath.client.XPathItem>
     */				
	Vector ContextItem = new Vector();
	
	/**
     * @gwt.typeArgs <java.lang.Integer>
     */		
	Vector ContextPosition = new Vector();

	/**
     * @gwt.typeArgs <java.lang.Integer>
     */	
	Vector ContextSize = new Vector();

	Boolean FilterMode = false;
	
	public XPathDynamicEnv(){
		; //just for variable initialisation so that the GWT compliler can recognise an uninitialised object's type 
	}
	
	public XPathDynamicEnv(XPathStaticEnv staticEnv, XPathSequence input, XPathSequence result)
	{
		if(!input.IsEmpty()){
			this.Focus = input;
			this.ContextItem.add(input.GetItemAt(0));
			this.ContextPosition.add(0);
			this.ContextSize.add(input.GetSize());
			this.FilterMode = false;
		}
		this.StatEnv = staticEnv;
		this.Init();
	}

	public void Init(){
		//TODO:
		// this.InitVariables(); 	
	};
	
	public void InitVariables(){ 
		//TODO:
		/*
		XSDType item = StatEnv.Types.find("dm:item").Value;
		XSDType node = StatEnv.Types.find("dm:node").Value;

		XPathVar var = new XPathVar();
		var.LocalName = "dot";
		var.Namespace = "fs";
		var.Type = item;
		var.Value.itemVal = null;
		this.Variables["fs:dot"] = var;
	 */			
		
	};
	
	public void SetVariable(String qname, Object val){
		XPathVar var = new XPathVar();
		var.QName = qname;
		var.Value = val;
		this.Variables.remove(qname);
		this.Variables.put(qname, var);		
	}
	
	//These were originally implemented in c++ with a union type
	//public void SetVariable(String qname, XPathSequence val){};
	//public void SetVariable(String qname, XPathItem val){};
}
